class code1 {
    //快慢指针，存在循环且重合的点为1，就是true
    public boolean isHappy(int n) {
        int fast = Happy(Happy(n));
        int slow = Happy(n);
        while(fast != slow) {
            slow = Happy(slow);
            fast = Happy(Happy(fast));
        }
        return fast==1?true:false;
    }
    public int Happy(int n) {
        int ret = 0;
        while(n!=0) {
            int x = n % 10;
            n /= 10;
            ret += Math.pow(x,2);
        }
        return ret;
    }
}